package utils;

import javax.servlet.http.Cookie;

/**
 * Cookie处理工具类
 */
public class CookieUtil {
    /**
     * 根据name查找到对应的Cookie
     * @param cookies
     * @param name
     * @return
     */
    public static Cookie findByCookie(Cookie[] cookies,String name)
    {
        if(cookies == null)
        {
            //这时候不存在cookie
            return null;
        }else {
            //遍历获取cookie
            for(Cookie cookie:cookies)
            {
                if(name.equals(cookie.getName()))
                {
                    return cookie;
                }
            }
            return null;//没有找到对应的cookie
        }

    }
}
